/*
ID: icerupt1
PROG: milk2
LANG: C++11
*/
#include <fstream>
#include <algorithm>

using namespace std;

struct interval
{
	int start;
	int end;
};

int main()
{
	ofstream fout ("milk2.out");
	ifstream fin ("milk2.in");
	int n;
	fin >> n;
	vector<interval> schedule;
	schedule.resize(n);
	for (int i = 0; i < n; i++)
		fin >> schedule[i].start >> schedule[i].end;
	sort(schedule.begin(), schedule.end(), [](interval a, interval b) {
			return a.start < b.start ||
					(a.start == b.start && a.end < b.end);
		});
	int max_length = schedule[0].end - schedule[0].start;
	for (int i = 1; i < n; i++) {
		if (schedule[i].start <= schedule[i-1].end) {
			schedule[i].start = schedule[i-1].start;
			schedule[i].end = max(schedule[i].end, schedule[i-1].end);
		}
		max_length = max(max_length, schedule[i].end - schedule[i].start);
	}
	fout << max_length << " ";

	max_length = 0;
	for (int i = 1; i < n; i++) {
		if (schedule[i].start > schedule[i-1].end)
			max_length = max(max_length, schedule[i].start - schedule[i-1].end);
		else
			schedule[i].end = max(schedule[i].end, schedule[i-1].end);
	}
	fout << max_length << endl;
}
